package com.epidemic.project.system.leave.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.epidemic.project.system.leave.domain.SysAskForLeave;
import com.epidemic.project.system.leave.service.ISysAskForLeaveService;
import com.epidemic.framework.web.controller.BaseController;
import org.springframework.stereotype.Controller;
import com.epidemic.framework.web.domain.AjaxResult;
import com.epidemic.common.utils.poi.ExcelUtil;
import com.epidemic.framework.web.page.TableDataInfo;

/**
 * 请假管理Controller
 *
 * @author sys
 * @date 2023-02-01
 */
@Controller
@RequestMapping("/system/leave")
public class SysAskForLeaveController extends BaseController
{
    private String prefix = "system/leave";

    @Autowired
    private ISysAskForLeaveService sysAskForLeaveService;

    @RequiresPermissions("system:leave:view")
    @GetMapping()
    public String leave()
    {
        return prefix + "/leave";
    }

    /**
     * 查询请假管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysAskForLeave sysAskForLeave)
    {
        startPage();
        List<SysAskForLeave> list = sysAskForLeaveService.selectSysAskForLeaveList(sysAskForLeave);
        return getDataTable(list);
    }

    /**
     * 导出请假管理列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysAskForLeave sysAskForLeave)
    {
        List<SysAskForLeave> list = sysAskForLeaveService.selectSysAskForLeaveList(sysAskForLeave);
        ExcelUtil<SysAskForLeave> util = new ExcelUtil<SysAskForLeave>(SysAskForLeave.class);
        return util.exportExcel(list, "leave");
    }

    /**
     * 新增请假管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存请假管理
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysAskForLeave sysAskForLeave)
    {
        return toAjax(sysAskForLeaveService.insertSysAskForLeave(sysAskForLeave));
    }

    /**
     * 修改请假管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysAskForLeave sysAskForLeave = sysAskForLeaveService.selectSysAskForLeaveById(id);
        mmap.put("sysAskForLeave", sysAskForLeave);
        return prefix + "/edit";
    }

    /**
     * 修改保存请假管理
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysAskForLeave sysAskForLeave)
    {
        return toAjax(sysAskForLeaveService.updateSysAskForLeave(sysAskForLeave));
    }

    /**
     * 删除请假管理
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysAskForLeaveService.deleteSysAskForLeaveByIds(ids));
    }
}
